package com.weigee.ktv.view.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import com.bumptech.glide.Glide
import com.weigee.ktv.R
import com.weigee.ktv.model.enums.ImagePreLoad
import com.weigee.ktv.model.enums.WeigeeHost
import kotlinx.android.synthetic.main.item_text.view.*
import skin.support.widget.SkinCompatFrameLayout

/**
 * Created by linde on 2017/5/31.
 *<p/>
 */
class TextItemView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : SkinCompatFrameLayout(context, attrs, defStyleAttr)
{
    init
    {
        LayoutInflater.from(context).inflate(R.layout.item_text, this, true)
        var text = resources.getString(R.string.app_name)
        var checked = false
        attrs?.let {
            val ta = context.obtainStyledAttributes(it, R.styleable.TextItemView)

            text = ta.getString(R.styleable.TextItemView_item_text_msg)
            checked = ta.getBoolean(R.styleable.TextItemView_item_text_checked, false)

            ta.recycle()
        }

        tv_msg.text = text
        Glide.with(context).load(WeigeeHost.TEST_IMAGE.url).asBitmap().placeholder(ImagePreLoad.IMAGE.res).into(iv_com)

        setTextChecked(checked)
    }

    fun setTextChecked(checked: Boolean)
    {
        tv_msg.isSelected = checked
    }
}